package com.tiancheng.trade.payment.enums;

import com.tiancheng.trade.commom.core.enums.BaseEnum;
import lombok.AllArgsConstructor;
import lombok.Getter;

import java.util.Arrays;
import java.util.Optional;

/**
 * paypal支付状态
 */
@Getter
@AllArgsConstructor
public enum PaypalStateEnum implements BaseEnum<String> {

    CREATED("CREATED", "创建支付成功"),
    SAVED("SAVED", "订单保存成功"),
    APPROVED("APPROVED", "确认付款"),
    VOIDED("VOIDED", "无效"),
    COMPLETED("COMPLETED","成功"),
    PAYER_ACTION_REQUIRED("PAYER_ACTION_REQUIRED", "付款人验证"),

    PENDING("PENDING","支付成功"),
    FAILED("FAILED", "支付失败"),

    //退款状态
    REFUND_CANCEL("CANCELLED", "退款取消"),
    REFUND_PENDING("PENDING", "待办"),
    REFUND_COMPLETED("COMPLETED", "退款完成"),


    //ipn回调
    IPN_COMPLETED("Completed","支付成功"),
    IPN_PENDING("Pending","待定"),
    IPN_REFUNDED("Refunded","退款成功"),
    IPN_REVERSED("Reversed","付款因退款或其他类型的冲销而被冲销"),//付款因退款或其他类型的冲销而被冲销。资金已从您的帐户余额中删除，并退还给买方
    IPN_CANCELED_REVERSAL("Canceled_Reversal","撤销已被取消"),//例如，您赢得了与客户的纠纷，并且撤回的交易资金已退还给您
    IPN_DENIED("Denied","付款被拒绝"),
    IPN_EXPIRED("Expired","此授权已过期，无法捕获"),
    IPN_CREATED("Created",""),//德国的ELV付款是通过Express Checkout进行的
    IPN_FAILED("Failed","付款失败"),//仅当付款是通过您客户的银行帐户进行的。
    IPN_PROCESSED("Processed","付款已被接受"),
    IPN_VOIDED("Voided","此授权已失效"),


    //ipn回调消息验证结果
    VERIFIED("VERIFIED","已验证"),
    INVALID("INVALID","无效"),

    //paypal查询状态
    GET_COMPLETED("COMPLETED", "此次捕获付款的资金已记入收款人的 PayPal 账户"),
    GET_DECLINED("DECLINED", "无法获取资金"),
    GET_PARTIALLY_REFUNDED("PARTIALLY_REFUNDED", "少于此捕获付款金额的金额部分退还给付款人"),
    GET_PENDING("PENDING", "这笔已捕获付款的资金尚未记入收款人的 PayPal 帐户"),
    GET_REFUNDED("REFUNDED", "大于或等于此捕获付款金额的金额已退还给付款人"),
    ;




    private String code;
    private String desc;

    public static String getDesc(String code) {
        Optional<PaypalStateEnum> found = Arrays.stream(PaypalStateEnum.values()).filter(c -> c.code.equals(code)).findFirst();
        if (found.isPresent()) {
            return found.get().getDesc();
        }
        return "";
    }
}
